home *** CD-ROM | disk | FTP | other *** search
/ Holt Researcher: American History / Holt Researcher: American History.iso / pc / modules / dbtable.dxr / 00005_table object.ls < prev    next >
Encoding:
Text File  |  2000-01-18  |  15.3 KB  |  553 lines

  1. property _me, pSelectChannel, pSelectionRect, pVThumbObj, pHThumbObj, pNArrowObj, pSArrowObj, pEArrowObj, pWArrowObj, pCopyButtonObj, pTracking, pSpanCorner, pSpanHeader, pBody, pRowHeader, pColumnHeader, pCorner, pScrollNeedsList, pOnStageRectList
  2. global gDBTableVarList
  3.  
  4. on new me, selectChannel, SpanCorner, SpanHeader, corner, colHeader, rowHeader, body, descendant
  5.   if objectp(descendant) then
  6.     _me = descendant
  7.   else
  8.     _me = me
  9.   end if
  10.   pSelectChannel = selectChannel
  11.   pBody = body
  12.   pRowHeader = rowHeader
  13.   pColumnHeader = colHeader
  14.   pCorner = corner
  15.   pSpanCorner = SpanCorner
  16.   pSpanHeader = SpanHeader
  17.   MyObj = getaProp(gDBTableVarList, GetObjProp())
  18.   SpriteList = GetSpriteList(MyObj)
  19.   controlList = GetControlList(MyObj)
  20.   VBedSp = getaProp(SpriteList, #VBed)
  21.   VThumbSp = getaProp(SpriteList, #VThumb)
  22.   NArrowSp = getaProp(SpriteList, #NorthArrow)
  23.   SArrowSp = getaProp(SpriteList, #SArrow)
  24.   pVBedObj = getaProp(controlList, VBedSp)
  25.   pVThumbObj = getaProp(controlList, VThumbSp)
  26.   pNArrowObj = getaProp(controlList, NArrowSp)
  27.   pSArrowObj = getaProp(controlList, SArrowSp)
  28.   HBedSp = getaProp(SpriteList, #HBed)
  29.   EArrowSp = getaProp(SpriteList, #EArrow)
  30.   WArrowSp = getaProp(SpriteList, #WArrow)
  31.   HThumbSp = getaProp(SpriteList, #HThumb)
  32.   pHBedObj = getaProp(controlList, HBedSp)
  33.   pEArrowObj = getaProp(controlList, EArrowSp)
  34.   pWArrowObj = getaProp(controlList, WArrowSp)
  35.   pHThumbObj = getaProp(controlList, HThumbSp)
  36.   pSelectionRect = rect(-1, -1, -1, -1)
  37.   pTracking = 0
  38.   return me
  39. end
  40.  
  41. on setSuperTable me
  42.   setSuperTable(pBody, _me)
  43.   setSuperTable(pRowHeader, _me)
  44.   setSuperTable(pColumnHeader, _me)
  45.   setSuperTable(pCorner, _me)
  46.   return me
  47. end
  48.  
  49. on SetPostShowProps me
  50.   SetPostShowProps(pSpanHeader)
  51.   SetPostShowProps(pCorner)
  52.   SetPostShowProps(pColumnHeader)
  53.   SetPostShowProps(pRowHeader)
  54.   SetPostShowProps(pBody)
  55.   MyObj = getaProp(gDBTableVarList, GetObjProp())
  56.   controlList = GetControlList(MyObj)
  57.   SpriteList = GetSpriteList(MyObj)
  58.   pScrollNeedsList = GetScrollNeeds(_me)
  59.   if getaProp(pScrollNeedsList, #v) then
  60.     VScrollCount = GetInvisibleRowCount(pBody)
  61.     ThumbSp = getaProp(SpriteList, #VThumb)
  62.     theThumbLoc = the locH of sprite ThumbSp
  63.     minPixel = the locV of sprite ThumbSp
  64.     maxPixel = the top of sprite getaProp(SpriteList, #SArrow) - (the height of sprite ThumbSp / 2)
  65.     resize(pVThumbObj, theThumbLoc, minPixel, maxPixel, 1, VScrollCount, 1, VScrollCount)
  66.   end if
  67.   if getaProp(pScrollNeedsList, #h) then
  68.     if IsTableVisible(pSpanHeader) then
  69.       HScrollCount = GetInvisibleColumnCount(pSpanHeader)
  70.     else
  71.       HScrollCount = GetInvisibleColumnCount(pBody)
  72.     end if
  73.     HScrollCount = max(HScrollCount, 2)
  74.     ThumbSp = getaProp(SpriteList, #HThumb)
  75.     theThumbLoc = the locV of sprite ThumbSp
  76.     minPixel = the locH of sprite ThumbSp
  77.     maxPixel = the left of sprite getaProp(SpriteList, #EArrow) - (the width of sprite ThumbSp / 2)
  78.     resize(pHThumbObj, theThumbLoc, minPixel, maxPixel, 1, HScrollCount, 1, HScrollCount)
  79.   end if
  80.   pCopyButtonObj = getaProp(controlList, getaProp(SpriteList, #CopyButton))
  81.   return me
  82. end
  83.  
  84. on condemn me
  85.   _me = 0
  86.   pNArrowObj = 0
  87.   pSArrowObj = 0
  88.   pEArrowObj = 0
  89.   pWArrowObj = 0
  90.   pVThumbObj = 0
  91.   pHThumbObj = 0
  92.   pRowHeader = 0
  93.   pColumnHeader = 0
  94.   pCorner = 0
  95.   pSpanCorner = 0
  96.   pSpanHeader = 0
  97.   pBody = 0
  98.   return me
  99. end
  100.  
  101. on CondemnList me, xList
  102.   MaxCount = count(xList)
  103.   repeat with rc = 1 to MaxCount
  104.     xObj = getAt(xList, rc)
  105.     condemn(xObj)
  106.     setAt(xList, rc, 0)
  107.   end repeat
  108.   return 0
  109. end
  110.  
  111. on Inscope me
  112.   puppetSprite(pSelectChannel, 1)
  113.   return me
  114. end
  115.  
  116. on outScope me
  117.   puppetSprite(pSelectChannel, 0)
  118.   return me
  119. end
  120.  
  121. on showMe me
  122.   set the rect of sprite pSelectChannel to getVisRect(_me, pSelectionRect)
  123.   updateStage()
  124.   return me
  125. end
  126.  
  127. on hideMe me
  128.   set the rect of sprite pSelectChannel to rect(0, 0, 0, 0)
  129.   updateStage()
  130.   return me
  131. end
  132.  
  133. on trackMouse me, startCell
  134.   pTracking = 1
  135.   resetSelection(me._me)
  136.   c = point(-1, -1)
  137.   currCell = startCell
  138.   setSelectionRect(me._me, startCell, currCell)
  139.   repeat while the mouseDown
  140.     currCell = getCurrCell(me._me, the mouseH, the mouseV)
  141.     if c <> currCell then
  142.       setSelectionRect(me._me, startCell, currCell)
  143.       set the rect of sprite pSelectChannel to getVisRect(_me, pSelectionRect)
  144.       updateStage()
  145.       c = currCell
  146.     end if
  147.   end repeat
  148.   setSelectionRect(me._me, startCell, currCell)
  149.   set the rect of sprite pSelectChannel to getVisRect(_me, pSelectionRect)
  150.   updateStage()
  151.   pTracking = 0
  152.   if checkIfSelected(me) then
  153.     enable(pCopyButtonObj)
  154.   else
  155.     disable(pCopyButtonObj)
  156.   end if
  157.   return me
  158. end
  159.  
  160. on getCurrCell me, h, v
  161.   if isAbove(pBody, v) then
  162.     currCell = AboveBody(me, h, v)
  163.   else
  164.     if not isBelow(pBody, v) then
  165.       if isLeftOf(pBody, h) then
  166.         currCell = LevelwithBodyHMinReached(me, h, v)
  167.       else
  168.         if isRightOf(pBody, h) then
  169.           if not maxReached(pHThumbObj) then
  170.             simulateClickOn(pEArrowObj)
  171.           end if
  172.           currCell = getMouseCell(pBody, h, v)
  173.         else
  174.           currCell = getMouseCell(pBody, h, v)
  175.         end if
  176.       end if
  177.     else
  178.       if isLeftOf(pColumnHeader, h) then
  179.         if not maxReached(pVThumbObj) then
  180.           simulateClickOn(pSArrowObj)
  181.         end if
  182.         if not minReached(pHThumbObj) then
  183.           simulateClickOn(pWArrowObj)
  184.           currCell = getMouseCell(pBody, h, v)
  185.         else
  186.           mouseCell = getMouseCell(pRowHeader, h, v)
  187.           currCell = point(0, getAt(mouseCell, 2))
  188.         end if
  189.       else
  190.         if isRightOf(pBody, h) then
  191.           if not maxReached(pVThumbObj) then
  192.             simulateClickOn(pSArrowObj)
  193.           end if
  194.           if not maxReached(pHThumbObj) then
  195.             simulateClickOn(pEArrowObj)
  196.           end if
  197.           currCell = getMouseCell(pBody, h, v)
  198.         else
  199.           if not maxReached(pVThumbObj) then
  200.             simulateClickOn(pSArrowObj)
  201.           end if
  202.           currCell = getMouseCell(pBody, h, v)
  203.         end if
  204.       end if
  205.     end if
  206.   end if
  207.   return currCell
  208. end
  209.  
  210. on AboveBody me, h, v
  211.   if isLeftOf(pBody, h) then
  212.     currCell = AboveBodyVMinReached(me, h, v)
  213.     currCell = AboveBodyHMinReached(me, h, v)
  214.   else
  215.     if isRightOf(pBody, h) then
  216.       if not minReached(pVThumbObj) then
  217.         simulateClickOn(pNArrowObj)
  218.         currCell = getMouseCell(pBody, h, v)
  219.       end if
  220.       if not maxReached(pHThumbObj) then
  221.         simulateClickOn(pEArrowObj)
  222.         currCell = getMouseCell(pBody, h, v)
  223.       else
  224.         mouseCell = getMouseCell(pColumnHeader, h, v)
  225.         currCell = point(getAt(mouseCell, 1), 0)
  226.       end if
  227.     else
  228.       if not minReached(pVThumbObj) then
  229.         simulateClickOn(pNArrowObj)
  230.         currCell = getMouseCell(pBody, h, v)
  231.       else
  232.         mouseCell = getMouseCell(pColumnHeader, h, v)
  233.         currCell = point(getAt(mouseCell, 1), 0)
  234.       end if
  235.     end if
  236.   end if
  237.   return currCell
  238. end
  239.  
  240. on AboveBodyVMinReached me, h, v
  241.   if not minReached(pVThumbObj) then
  242.     simulateClickOn(pNArrowObj)
  243.     mouseCell = getMouseCell(pRowHeader, h, v)
  244.     currCell = point(0, getAt(mouseCell, 2))
  245.   else
  246.     currCell = point(0, 0)
  247.   end if
  248.   return currCell
  249. end
  250.  
  251. on AboveBodyHMinReached me, h, v
  252.   if not minReached(pHThumbObj) then
  253.     simulateClickOn(pWArrowObj)
  254.     mouseCell = getMouseCell(pColumnHeader, h, v)
  255.     currCell = point(0, getAt(mouseCell, 2))
  256.   else
  257.     currCell = point(0, 0)
  258.   end if
  259.   return currCell
  260. end
  261.  
  262. on LevelwithBodyHMinReached me, h, v
  263.   if not minReached(pHThumbObj) then
  264.     simulateClickOn(pWArrowObj)
  265.     currCell = getMouseCell(pBody, h, v)
  266.   else
  267.     mouseCell = getMouseCell(pRowHeader, h, v)
  268.     currCell = point(0, getAt(mouseCell, 2))
  269.   end if
  270.   return currCell
  271. end
  272.  
  273. on doRollover me
  274.   return me
  275. end
  276.  
  277. on ScrollToStart me
  278.   if not minReached(pVThumbObj) then
  279.     scrollToTop(pSpanHeader)
  280.     scrollToTop(pRowHeader)
  281.     scrollToTop(pBody)
  282.   end if
  283.   if not minReached(pHThumbObj) then
  284.     scrollToLeft(pSpanHeader)
  285.     scrollToLeft(pColumnHeader)
  286.     scrollToLeft(pBody)
  287.   end if
  288. end
  289.  
  290. on scrollUp me
  291.   scrollUp(pBody)
  292.   scrollUp(pRowHeader)
  293.   if not pTracking then
  294.     set the rect of sprite pSelectChannel to getVisRect(_me, pSelectionRect)
  295.   end if
  296.   updateStage()
  297.   return me
  298. end
  299.  
  300. on scrollDown me
  301.   scrollDown(pRowHeader)
  302.   scrollDown(pBody)
  303.   if not pTracking then
  304.     set the rect of sprite pSelectChannel to getVisRect(_me, pSelectionRect)
  305.   end if
  306.   updateStage()
  307.   return me
  308. end
  309.  
  310. on scrollLeft me
  311.   ScrollIncrement = GetScrollLeftIncrement(pSpanHeader)
  312.   scrollLeft(pSpanHeader, ScrollIncrement)
  313.   scrollLeft(pColumnHeader, ScrollIncrement)
  314.   scrollLeft(pBody, ScrollIncrement)
  315.   if not pTracking then
  316.     set the rect of sprite pSelectChannel to getVisRect(_me, pSelectionRect)
  317.   end if
  318.   updateStage()
  319.   return me
  320. end
  321.  
  322. on scrollRight me
  323.   ScrollIncrement = GetScrollRightIncrement(pSpanHeader)
  324.   if getNumColumns(pSpanHeader) > 1 then
  325.     scrollRight(pSpanHeader, ScrollIncrement)
  326.   end if
  327.   scrollRight(pColumnHeader, ScrollIncrement)
  328.   scrollRight(pBody, ScrollIncrement)
  329.   if not pTracking then
  330.     set the rect of sprite pSelectChannel to getVisRect(_me, pSelectionRect)
  331.   end if
  332.   updateStage()
  333.   return me
  334. end
  335.  
  336. on getTopRow me
  337.   return getTopRow(pBody)
  338. end
  339.  
  340. on getLeftColumn me
  341.   return getLeftColumn(pBody)
  342. end
  343.  
  344. on resetSelection me
  345.   pSelectionRect = rect(-1, -1, -1, -1)
  346.   set the rect of sprite pSelectChannel to rect(0, 0, 0, 0)
  347.   return me
  348. end
  349.  
  350. on setSelectionRect me, cell1, cell2
  351.   p1 = duplicate(cell1)
  352.   p2 = duplicate(cell2)
  353.   if getAt(p1, 1) > getAt(p2, 1) then
  354.     temp = getAt(p2, 1)
  355.     setAt(p2, 1, getAt(p1, 1))
  356.     setAt(p1, 1, temp)
  357.   end if
  358.   if getAt(p1, 2) > getAt(p2, 2) then
  359.     temp = getAt(p2, 2)
  360.     setAt(p2, 2, getAt(p1, 2))
  361.     setAt(p1, 2, temp)
  362.   end if
  363.   pSelectionRect = rect(p1, p2)
  364.   return me
  365. end
  366.  
  367. on getVisRect me, theRect
  368.   R = rect(0, 0, 0, 0)
  369.   if theRect <> rect(-1, -1, -1, -1) then
  370.     if (theRect.left > 0) and (theRect.top > 0) then
  371.       R = getVisRect(pBody, theRect)
  372.     end if
  373.     if (theRect.left = 0) and (theRect.top > 0) then
  374.       r1 = getVisRect(pRowHeader, rect(1, getAt(theRect, 2), 1, getAt(theRect, 4)))
  375.       r2 = getVisRect(pBody, rect(1, getAt(theRect, 2), getAt(theRect, 3), getAt(theRect, 4)))
  376.       R = unionVisRect(_me, r1, r2)
  377.     end if
  378.     if (theRect.left > 0) and (theRect.top = 0) then
  379.       r1 = getVisRect(pColumnHeader, rect(getAt(theRect, 1), 1, getAt(theRect, 3), 1))
  380.       r2 = getVisRect(pBody, rect(getAt(theRect, 1), 1, getAt(theRect, 3), getAt(theRect, 4)))
  381.       R = unionVisRect(_me, r1, r2)
  382.     end if
  383.     if (theRect.left = 0) and (theRect.top = 0) then
  384.       r1 = getVisRect(pCorner, rect(1, 1, 1, 1))
  385.       if (theRect.right = 0) and (theRect.bottom = 0) then
  386.         nothing()
  387.       else
  388.         if theRect.right = 0 then
  389.           r2 = getVisRect(pRowHeader, rect(1, getAt(theRect, 2), 1, getAt(theRect, 4)))
  390.         else
  391.           if theRect.bottom = 0 then
  392.             r2 = getVisRect(pColumnHeader, rect(getAt(theRect, 1), 1, getAt(theRect, 3), 1))
  393.           else
  394.             r2 = getVisRect(pBody, rect(1, 1, getAt(theRect, 3), getAt(theRect, 4)))
  395.             r3 = getVisRect(pRowHeader, rect(1, getAt(theRect, 2), 1, getAt(theRect, 4)))
  396.             r4 = getVisRect(pColumnHeader, rect(getAt(theRect, 1), 1, getAt(theRect, 3), 1))
  397.             r2 = unionVisRect(_me, r2, r3)
  398.             r2 = unionVisRect(_me, r2, r4)
  399.           end if
  400.         end if
  401.       end if
  402.       R = unionVisRect(_me, r1, r2)
  403.     end if
  404.   end if
  405.   return R
  406. end
  407.  
  408. on unionVisRect me, rect1, rect2
  409.   R = rect(0, 0, 0, 0)
  410.   if voidp(rect1) or (rect1 = rect(0, 0, 0, 0)) then
  411.     return rect2
  412.   else
  413.     if voidp(rect2) or (rect2 = rect(0, 0, 0, 0)) then
  414.       return rect1
  415.     else
  416.       return union(rect1, rect2)
  417.     end if
  418.   end if
  419. end
  420.  
  421. on MapCharsToPlatform me
  422.   MapCharsToPlatform(pRowHeader)
  423.   MapCharsToPlatform(pBody)
  424.   return me
  425. end
  426.  
  427. on GetScrollNeeds me
  428.   return GetScrollNeeds(pBody)
  429. end
  430.  
  431. on setOnStageRectList me, Var
  432.   pOnStageRectList = Var
  433. end
  434.  
  435. on GetOnStageRectList me
  436.   return pOnStageRectList
  437. end
  438.  
  439. on SizeTable me, size
  440.   if size = 1 then
  441.     SetTableMin(me)
  442.   else
  443.     if getaProp(pScrollNeedsList, #h) or getaProp(pScrollNeedsList, #v) then
  444.       MyObj = getaProp(gDBTableVarList, GetObjProp())
  445.       SpriteList = GetSpriteList(MyObj)
  446.       if getaProp(pScrollNeedsList, #h) then
  447.         xMax = GetMaxVisibleXPixel(pBody, 604)
  448.       end if
  449.       if getaProp(pScrollNeedsList, #v) then
  450.         yMax = 384 - member(the member of sprite getaProp(SpriteList, #Footnote)).height
  451.         yMax = GetMaxVisibleYPixel(pBody, yMax)
  452.       end if
  453.       SetTableMax(me, xMax, yMax)
  454.     end if
  455.   end if
  456.   disable(pCopyButtonObj)
  457. end
  458.  
  459. on SetTableMin me
  460.   EvalSetTableMin(pSpanHeader)
  461.   SetTableMin(pColumnHeader)
  462.   SetTableMin(pRowHeader)
  463.   SetTableMin(pBody)
  464.   return me
  465. end
  466.  
  467. on SetTableMax me, xMax, yMax
  468.   if not voidp(xMax) then
  469.     EvalSetTableMax(pSpanHeader, xMax)
  470.     SetTableMax(pColumnHeader, xMax)
  471.   end if
  472.   SetTableMax(pRowHeader, xMax, yMax)
  473.   SetTableMax(pBody, xMax, yMax)
  474. end
  475.  
  476. on GetSpanCornerNewRect me
  477.   return GetNewRect(pSpanCorner)
  478. end
  479.  
  480. on GetSpanHeaderNewRect me
  481.   return GetNewRect(pSpanHeader)
  482. end
  483.  
  484. on GetCornerNewRect me
  485.   return GetNewRect(pCorner)
  486. end
  487.  
  488. on GetColumnHeaderNewRect me
  489.   return GetNewRect(pColumnHeader)
  490. end
  491.  
  492. on GetRowHeaderNewRect me
  493.   return GetNewRect(pRowHeader)
  494. end
  495.  
  496. on GetBodyNewRect me
  497.   return GetNewRect(pBody)
  498. end
  499.  
  500. on buttonLoc me
  501.   return me
  502. end
  503.  
  504. on checkIfSelected me
  505.   return pSelectionRect <> rect(-1, -1, -1, -1)
  506. end
  507.  
  508. on getSelectedData me
  509.   if pSelectionRect <> rect(-1, -1, -1, -1) then
  510.     dataList = []
  511.     append(dataList, pSelectionRect)
  512.     if (pSelectionRect.left > 0) and (pSelectionRect.top > 0) then
  513.       append(dataList, getSelectedData(pBody, pSelectionRect))
  514.     else
  515.       if (pSelectionRect.left > 0) and (pSelectionRect.top = 0) then
  516.         data = getSelectedData(pColumnHeader, rect(getAt(pSelectionRect, 1), 1, getAt(pSelectionRect, 3), 1))
  517.         data = quickUnion(data, getSelectedData(pBody, rect(getAt(pSelectionRect, 1), 1, getAt(pSelectionRect, 3), getAt(pSelectionRect, 4))))
  518.         append(dataList, data)
  519.       else
  520.         if (pSelectionRect.left = 0) and (pSelectionRect.top > 0) then
  521.           data = []
  522.           rowData = getSelectedData(pRowHeader, rect(1, getAt(pSelectionRect, 2), 1, getAt(pSelectionRect, 4)))
  523.           bodyData = getSelectedData(pBody, rect(1, getAt(pSelectionRect, 2), getAt(pSelectionRect, 3), getAt(pSelectionRect, 4)))
  524.           numRows = getAt(pSelectionRect, 4) - getAt(pSelectionRect, 2) + 1
  525.           numCols = getAt(pSelectionRect, 3)
  526.           repeat with i = 1 to numRows
  527.             append(data, getAt(rowData, i))
  528.             repeat with j = 1 to numCols
  529.               append(data, getAt(bodyData, ((i - 1) * numCols) + j))
  530.             end repeat
  531.           end repeat
  532.           append(dataList, data)
  533.         else
  534.           data = getSelectedData(pCorner, rect(1, 1, 1, 1))
  535.           data = quickUnion(data, getSelectedData(pColumnHeader, rect(1, 1, getAt(pSelectionRect, 3), 1)))
  536.           rowData = getSelectedData(pRowHeader, rect(1, 1, 1, getAt(pSelectionRect, 4)))
  537.           bodyData = getSelectedData(pBody, rect(1, 1, getAt(pSelectionRect, 3), getAt(pSelectionRect, 4)))
  538.           numRows = getAt(pSelectionRect, 4)
  539.           numCols = getAt(pSelectionRect, 3)
  540.           repeat with i = 1 to numRows
  541.             append(data, getAt(rowData, i))
  542.             repeat with j = 1 to numCols
  543.               append(data, getAt(bodyData, ((i - 1) * numCols) + j))
  544.             end repeat
  545.           end repeat
  546.           append(dataList, data)
  547.         end if
  548.       end if
  549.     end if
  550.   end if
  551.   return dataList
  552. end
  553.